package checkers3d.logic;

import checkers3d.presentation.GUITextbox;
import checkers3d.presentation.IRenderResource;
import checkers3d.presentation.RenderResourceBitmap;
import java.util.*;

/**
 * Player represents a player of the game with certain attributes such as the
 * their name, password, administrative capability, a list of their statistics,
 * a list of their pieces that are currently on the board, and a list of their
 * pieces that have been captured or removed from the board.
 *
 * @author      Sean Keel
 */
public class Player {

    /*
     * Administrative attribute of this Player.
     */
    private boolean admin;

    /*
     * This Player's name as a string.
     */
    private String name;

    /*
     * This Player's encrypted password as a string.
     */
    private String encryptedPassword;

    /*
     * A linked list of board objects that are inactive in the game.
     */
    private LinkedList<IBoardObject> deadPieces;

    /*
     * A linked list of board objects that are active in the game.
     */
    private LinkedList<IBoardObject> livingPieces;

    /**
     * A IRenderResource with the current icon for this player's checker pieces.
     */
    private IRenderResource iconChecker = null;

    /**
     * A IRenderResource with the current icon for this player's king pieces.
     */
    private IRenderResource iconKing = null;

    /**
     * A IRenderResource with the current icon for this player's wall pieces
     */
    private IRenderResource iconWall = null;

    /**
     * A IRenderResource with the current icon for this player's safezones.
     */
    private IRenderResource iconSafe = null;

    /**
     * A IRenderResource with the current icon for this player's mines.
     */
    private IRenderResource iconMine = null;

    /**
     * A IRenderResource with the current icon for the winning effect.
     */
    private IRenderResource iconWin = null;

    /*
     * Class constructor which sets starting attributes for this Player.
     */
    public Player(String name, String password){
        setName(name);
        setPassword(password);
        deadPieces = null;
        livingPieces = null;
    }

    /**
     * Checks to see if this Player has administrative capability.
     *
     * @return Whether the Player has administrative capability by returning
     * true or false
     */
    public boolean isAdmin() {
        return admin;
    }

    /**
     * Enables this Player's administrative capability by setting the admin
     * parameter to true.
     */
    public void addAdminCapability(){
        admin = true;
    }

    /**
     * Removes this Player's administrative capability by setting the admin
     * parameter to false.
     */
    public void removeAdminCapability(){
        admin = false;
    }

    /**
     * Returns the name of this Player.
     *
     * @return The name of this Player as a string.
     */
    public String getName(){
        return name;
    }
    
    /**
     * Stores name for this Player.
     *
     * @param username The name of this Player.
     */
    public void setName(String username){
        name = username;
    }

    /**
     * Returns the password for this Player.
     *
     * @return The encrypted password for this Player as a string.
     */
    public String getPassword(){
        return encryptedPassword;
    }

    /**
     * Stores password for this Player.
     *
     * @param password The encrypted password for this Player.
     */
    public void setPassword(String password){
        encryptedPassword = password;
    }

    /**
     * Adds a piece to the list of pieces that are not playable in the game
     * and removes the corresponding living piece.
     *
     * @param livingBoardObject A board object such as a checker piece or mine
     */
    public void addDeadPiece(IBoardObject boardObject){
        deadPieces.add(boardObject);
        removeLivingPiece(boardObject);
    }

    /**
     * Adds a piece to the list of pieces currently in the game.
     *
     * @param livingBoardObject A board object such as a checker piece or mine
     */
    public void addLivingPiece(IBoardObject livingBoardObject){
        livingPieces.add(livingBoardObject);
    }

    /**
     * Removes a piece from the list of pieces currently in the game.
     *
     * @param livingBoardObject A board object such as a checker piece or mine
     */
    public void removeLivingPiece(IBoardObject livingBoardObject){
        livingPieces.remove(livingBoardObject);
    }

    /**
     * Loads a bitmap and sets it as the RenderResource for this player's
     * checkers.
     *
     * @param icon Filename of bitmap.
     */
    public void setCheckerRR(String icon)
    {
        iconChecker = new RenderResourceBitmap(icon);
    }

    /**
     * Returns an IRenderResource for appearance of this player's checkers.
     *
     * @return IRenderResource for appearance of this player's checkers.
     */
    public IRenderResource getCheckerRR()
    {
        return iconChecker;
    }

    /**
     * Loads a bitmap and sets it as the RenderResource for this player's
     * kingss.
     *
     * @param icon Filename of bitmap.
     */
    public void setKingRR(String icon)
    {
        iconKing = new RenderResourceBitmap(icon);
    }

    /**
     * Returns an IRenderResource for appearance of this player's kings.
     *
     * @return IRenderResource for appearance of this player's kings.
     */
    public IRenderResource getKingRR()
    {
        return iconKing;
    }

    /**
     * Loard a bitmap and sets it as the RenderResource for this player's
     * Walls.
     *
     * @param icon Filename of bitmap.
     */
    public void setWallRR(String icon)
    {
        iconWall = new RenderResourceBitmap(icon);
    }

    /**
     * Returns an IRenderResource for appearance of this player's walls.
     *
     * @return IRenderResource for appearance of this player's walls.
     */

    public IRenderResource getWallRR()
    {
        return iconWall;
    }

    /**
     * Loard a bitmap and sets it as the RenderResource for this player's
     * Safezones.
     *
     * @param icon Filename of bitmap.
     */
    public void setSafeRR(String icon)
    {
        iconSafe = new RenderResourceBitmap(icon);
    }

    /**
     * Returns an IRenderResource for appearance of this player's safezones.
     *
     * @return IRenderResource for appearance of this player's safezones.
     */

    public IRenderResource getSafeRR()
    {
        return iconSafe;
    }

    /**
     * Loard a bitmap and sets it as the RenderResource for this player's
     * mines.
     *
     * @param icon Filename of bitmap.
     */
    public void setMineRR(String icon)
    {
        iconMine = new RenderResourceBitmap(icon);
    }

    /**
     * Returns an IRenderResource for appearance of this player's mines.
     *
     * @return IRenderResource for appearance of this player's mines.
     */
    public IRenderResource getMineRR()
    {
        return iconMine;
    }

    /**
     * Loard a bitmap and sets it as the RenderResource for this player's
     * win effect.
     *
     * @param icon Filename of bitmap.
     */
    public void setWinRR(String icon)
    {
        iconWin = new RenderResourceBitmap(icon);
    }

    /**
     * Returns an IRenderResource for appearance of this player's win effect.
     *
     * @return IRenderResource for appearance of this player's win effect.
     */
    public IRenderResource getWinRR()
    {
        return iconWin;
    }

    /**
     * Returns a string containing data about this object needed to save it's
     * state.
     *
     * @return String with object's name.
     */
    public String getDataAsString()
    {
        return name;
    }

    /**
     * Returns a string of information about this class containing
     * the class name.
     *
     * @return  Returns a string representation of this class.
     */
    @Override
    public String toString(){
        return getClass().getName();
    }
}
